/*
 * ChatTherah.java
 *
 * Created on 2007年5月14日, 下午1:10
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.ecomm.chat.manager;

import com.ecomm.chat.pojo.ChatMessage;

/**
 *  只为保存消息单独新建一个线程
 *
 * <p>Title: 易讯聊天系统</p>
 * <p>Description:
 *  易讯聊天系统
 * </p>
 * <p>Copyright: Copyright (c) 2007</p>
 * <p>Company: 联合易讯 </p>
 * @author <font color='blue'>pijunliang</font> &nbsp&nbsp<a href="mailto:pijunliang@hotmail.com">pijunliang@hotmail.com</a>
 * @version 1.0
 * @since 2007年5月14日, 下午1:10
 */
public class ChatThread  extends Thread{
  
  /** Creates a new instance of ChatTherah */
  private ChatMessage chatMessage;
  private String action;
  private String id;
  private String sendUserid;
  
  public ChatThread() {
  }
  public ChatThread(ChatMessage chatMessage) {
    this.chatMessage=chatMessage;
  }
  public ChatThread(ChatMessage chatMessage,String action) {
    this.chatMessage=chatMessage;
    this.action = action;
  }
  public ChatThread(String id,String action,String sendUserid) {
    this.id=id;
    this.action = action;
    this.sendUserid=sendUserid;
  }
  public void start(ChatMessage chatMessage){
    this.chatMessage= chatMessage;
    start();
  }
  public void run() {
    if(action != null && action.equals("enter")){ //加入聊天实例
      ChatListenManager.getInstance().jionPushlet(id,sendUserid);
    }else if(action != null && action.equals("exit")){//退出聊天实例
      ChatListenManager.getInstance().LeavePushlet(id,sendUserid);
    }else if(action != null && action.equals("send")){//发送消息
      ChatMessageManager.getInstance().saveChat(chatMessage);
    }
  }
}
